/**
 * author: 何其沆(pooky)
 * desc: Vuex - PhaseManagement模块
 * date: 2021-11-19
 */
import { post } from '@/utils/request.js'
import api from '@/config/index.js'

export default {
  state: () => {
    return {
      // 年数据
      yearData: [],
      // 季度数据
      quarterData: [],
      // 月数据
      monthData: [],
      // 管理端年数据
      adminYearData: [],
      // 管理端季度数据
      adminQuarterData: [],
      // 管理端月数据
      adminMonthData: [],

      flag: 0
    }
  },
  mutations: {
    /**
     * PhaseManagement年数据
     * @param state
     * @param yearData
     */
    YEAR_DATA(state, yearData) {
      state.yearData = yearData
    },
    /**
     * PhaseManagement季度数据
     * @param state
     * @param quarterData
     */
    QUARTER_DATA(state, quarterData) {
      state.quarterData = quarterData
    },
    /**
     * PhaseManagement月数据
     * @param state
     * @param monthData
     */
    MONTH_DATA(state, monthData) {
      state.monthData = monthData
    },
    /**
     * 管理端PhaseManagement年数据
     * @param state
     * @param adminYearData
     * @constructor
     */
    ADMIN_YEAR_DATA(state, adminYearData) {
      state.adminYearData = adminYearData
    },
    /**
     * 管理端PhaseManagement季度数据
     * @param state
     * @param adminQuarterData
     * @constructor
     */
    ADMIN_QUARTER_DATA(state, adminQuarterData) {
      state.adminQuarterData = adminQuarterData
    },
    /**
     * 管理端PhaseManagement季度数据
     * @param state
     * @param adminMonthData
     * @constructor
     */
    ADMIN_MONTH_DATA(state, adminMonthData) {
      state.adminMonthData = adminMonthData
    },

    FLAG(state, flag) {
      state.flag = flag
    }
  },
  actions: {
    /**
     * PhaseManagement年数据
     * @param commit
     * @param data
     * @returns {Promise<void>}
     */
    async setYearData({ commit }, data) {
      await post(api.API_VERSION + '/PhaseManagement/QueryYearData', data, false).then(res => {
        if (res.code === 2000) {
          commit('YEAR_DATA', res)
        }
      })
    },
    /**
     * PhaseManagement季度数据
     * @param commit
     * @param data
     * @returns {Promise<void>}
     */
    async setQuarterData({ commit }, data) {
      await post(api.API_VERSION + '/PhaseManagement/QueryQuarterlyData', data, false).then(res => {
        if (res.code === 2000) {
          commit('QUARTER_DATA', res)
        }
      })
    },
    /**
     * PhaseManagement月数据
     * @param commit
     * @param data
     * @returns {Promise<void>}
     */
    async setMonthData({ commit }, data) {
      await post(api.API_VERSION + '/PhaseManagement/QueryMonthPhaseData', data, false).then(res => {
        if (res.code === 2000) {
          commit('MONTH_DATA', res)
        }
      })
    },
    /**
     * 管理端PhaseManagement年数据
     * @param commit
     * @param data
     * @returns {Promise<void>}
     */
    async setAdminYearData({ commit }, data) {
      await post(api.API_VERSION + '/Admin/PhaseManagement/QueryYearData', data, false).then(res => {
        if (res.code === 2000) {
          commit('ADMIN_YEAR_DATA', res)
        }
      })
    },
    /**
     * 管理端PhaseManagement季度数据
     * @param commit
     * @param data
     * @returns {Promise<void>}
     */
    async setAdminQuarterData({ commit }, data) {
      await post(api.API_VERSION + '/Admin/PhaseManagement/QueryQuarterlyData', data, false).then(res => {
        if (res.code === 2000) {
          commit('ADMIN_QUARTER_DATA', res)
        }
      })
    },
    /**
     * 管理端PhaseManagement月数据
     * @param commit
     * @param data
     * @returns {Promise<void>}
     */
    async setAdminMonthData({ commit }, data) {
      await post(api.API_VERSION + '/Admin/PhaseManagement/QueryMonthPhaseData', data, false).then(res => {
        if (res.code === 2000) {
          commit('ADMIN_MONTH_DATA', res)
        }
      })
    },
    async setFlag({ commit }, data) {
      commit('FLAG', data)
    }
  }
}
